package com.tajiang.business.setting.dialog;

import android.app.Dialog;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.TextView;

import com.tajiang.business.R;
import com.tajiang.business.common.utils.SharedPreferencesUtils;
import com.tajiang.business.common.utils.ToastUtils;
import com.tajiang.business.common.widget.SwitchView;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * Created by Administrator on 2016/8/23.
 */
public class AutoPrintDialog extends Dialog {

    public static final boolean OPEN_AUTO_PRINT = true;
    public static final boolean CLOSE_AUTO_PRINT = false;
    private boolean state;

    @BindView(R.id.tv_show_msg)
    TextView tvShowMsg;
    @BindView(R.id.btn_cancel)
    TextView btnCancel;
    @BindView(R.id.btn_ensure)
    TextView btnEnsure;

    SwitchView svPrint;
    UpdateStateListener updateStateListener;

    public void setUpdateStateListener(UpdateStateListener updateStateListener) {
        this.updateStateListener = updateStateListener;
    }

    public interface UpdateStateListener {
        public void updateState();
    }

    public AutoPrintDialog(Context context, SwitchView svPrint) {
        super(context,R.style.dialog_operate);
        this.svPrint = svPrint;
        View view = LayoutInflater.from(context).inflate(R.layout.dialog_auto_print_setting, null);
        setContentView(view);
        ButterKnife.bind(this);

        initView();
    }

    private void initView() {
        this.setCancelable(false);
        if (svPrint.isOpened() == OPEN_AUTO_PRINT){
            tvShowMsg.setText("关闭后不可自动接单打\n\n确定关闭吗？");
            btnEnsure.setText("关闭");
            btnEnsure.setTextColor(getContext().getResources().getColor(R.color.red_orange));
        } else {
            tvShowMsg.setText("开启后可自动接单并打印\n\n确定开启吗？");
            btnEnsure.setText("开启");
            btnEnsure.setTextColor(getContext().getResources().getColor(R.color.green_light));
        }
    }

    public void setTextView(String msg) {
        tvShowMsg.setText(msg);
    }

    @OnClick(R.id.btn_cancel)
    public void onCancelClick() {
        this.dismiss();
    }

    @OnClick(R.id.btn_ensure)
    public void onConfirmClick() {
        svPrint.setOpened(!svPrint.isOpened());
        SharedPreferencesUtils.put(SharedPreferencesUtils.AUTO_PRINT, svPrint.isOpened());
        this.dismiss();
    }
}